<template>
	<view>
		<view class="zabj">
			<view @click="on_url(user?'../../page1/user_set':'../../pages/banmi/user_login')" class="flex j-f pt2"
				style="">
				<image style="width: 60rpx;height: 60rpx;padding-right:30rpx;" src="../../static/tab/shezhi.png"></image>
			</view>
			<view @click="on_url(user?'../../pages/banmi/user_set':'../../pages/banmi/user_login')" class=" flex a-c"
				style="padding-top: 10rpx;padding-right: 60rpx;padding-left: 60rpx;">
				<view class="">
					<image class="q_y" v-if="user" :src="user.itype==1?user.header:business.pic"
						style="width: 130rpx;height: 130rpx;border:3px solid #fff;">
					</image>
					<image class="q_y" v-if="!user" src="../../static/login1/face.png" style="width: 130rpx;height: 130rpx;">
					</image>
				</view>
				<view class="ml20" style="margin-top: -10rpx;">
					<text class="w800" style="font-size: 40rpx;color: #fff;">{{
						user?(user.itype==1?user.nickname:(business?business.name:user.nickname)):'请登录'
					}}</text>
					<view class="cff pt1">
					</view>
				</view>
			</view>
			<!-- :class="user.itype==1?'money':'moneys'" -->
			<view class="money" v-if="user">
				<text>当前余额: <text>{{fundsDTO.currencyAvailableShow||0}}</text>花瓣</text>
				<text v-if="user.itype==2">充值总额: <text>{{fundsDTO.currencyTotalShow||0}}</text></text>
				<text v-if="user">累计提现: <text>{{fundsDTO.cashBackShow||0}}</text></text>
			</view>
		</view>
		<view class="p2">
			<view v-if="user.itype" class="p20 b_y" style="margin-top:-120rpx;background-color: #fff;">
				<view @click="on_url('../../pages/views/withdrawal')" class="p20 borde">
					<view class="flex j-b a-c">
						<view class="flex a-c">
							<text class="ml1 f30">提现</text>
						</view>
						<view class="">
							<image style="width: 30rpx;height: 30rpx;" src="../../static/tab/you.png"></image>
						</view>
					</view>
				</view>
				<view v-if="user.itype==2" @click="on_url('../../pages/views/refill')" class="p20 borde">
					<view class="flex j-b a-c">
						<view class="flex a-c">
							<text class="ml1 f30">商家充值</text>
						</view>
						<view class="">
							<image style="width: 30rpx;height: 30rpx;" src="../../static/tab/you.png"></image>
						</view>
					</view>
				</view>
				<view @click="on_url('/pages/views/detail')" class="p20 borde">
					<view class="flex j-b a-c">
						<view class="flex a-c">
							<text class="ml1 f30">交易明细</text>
						</view>
						<view class="">
							<image style="width: 30rpx;height: 30rpx;" src="../../static/tab/you.png"></image>
						</view>
					</view>
				</view>
				<view v-if="user.itype==1" @click="business.status==0?shz():on_url('../../pages/views/shop_add')"
					class="p20 borde">
					<view class="flex j-b a-c">
						<view class="flex a-c">
							<text class="ml1 f30">商户入驻</text>
						</view>
						<view class="">
							<image style="width: 30rpx;height: 30rpx;" src="../../static/tab/you.png"></image>
						</view>
					</view>
				</view>
				<view v-if="user.itype==2" @click="on_url('../../pages/views/activity_add')" class="p20 borde">
					<view class="flex j-b a-c">
						<view class="flex a-c">
							<text class="ml1 f30">创建活动</text>
						</view>
						<view class="">
							<image style="width: 30rpx;height: 30rpx;" src="../../static/tab/you.png"></image>
						</view>
					</view>
				</view>
				<view @click="on_url('../../pages/views/advertising')" class="p20 borde">
					<view class="flex j-b a-c">
						<view class="flex a-c">
							<text class="ml1 f30">视频广告</text>
						</view>
						<view class="">
							<image style="width: 30rpx;height: 30rpx;" src="../../static/tab/you.png"></image>
						</view>
					</view>
				</view>
				<view @click="on_url('../../pages/views/advertising')" class="p20 borde">
					<view class="flex j-b a-c">
						<view class="flex a-c">
							<button class="service" type="default" open-type="contact">联系客服</button>
						</view>
						<view class="">
							<image style="width: 30rpx;height: 30rpx;" src="../../static/tab/you.png"></image>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				user: {},
				business: {},
				fundsDTO: {},
				token: ''
			}
		},
		onShow() {
			if (uni.getStorageSync('Token')) { //有数据就更新
				this.init();
			} else {
				this.user = this.business = this.fundsDTO = this.token = ''
			}
		},
		onLoad() {
			var that = this;
			this.user = ''
			this.business = ''
			this.$module.ifToken(res => {
				if (res == 1) {
					this.$module.navigateTo('/pages/banmi/user_login')
				} else if (res == 2) {
					this.init();
				}
			})
		},
		methods: {
			shz() {
				this.$module.showToast('商户审核中...')
			},
			service() {
				wx.openCustomerServiceChat({
					idcorpId: 'xxx', //企业微信的企业
					extInfo: {
						url: 'https://xxx'
					}, //客服链接
					success: (e) => {
						console.log('e', e)
					},
					fail: (err) => {
						console.log('err', err)
					}
				})
			},
			init() { //查询用户信息
				const that = this
				this.Htpp.user_info().then(res => {
					this.$module.sm(res, 2, ret => {
						let data = ret
						that.user = data.data.user
						if (data.data.business) {
							that.business = data.data.business
							uni.setStorageSync('business', data.data.business)
						}
						uni.setStorageSync('user', data.data.user)
						uni.setStorageSync('fundsDTO', data.data.fundsDTO)
						that.fundsDTO = data.data.fundsDTO
						that.getuser(data.data.user.id)
					})
				})
			},
			article_view(index) {
				uni.navigateTo({
					url: '/pages/banmi/article_view?id=' + index
				})
			},
			getuser(id) { //查询用户信息
				var that = this;
				this.Htpp.user_msg(id).then(ret => {
					this.$module.sm(ret, 2, ret => {

					})
				})
			},
			on_url(url) {
				const that = this
				// this.$module.ifTokens(res => {
				// 	if (res == 1) {
				// 		this.$module.navigateTo('/pages/banmi/user_login')
				// 	} else if (res == 2) {
				that.$module.navigateTo(url)
				// 	}
				// })
			}
		}
	}
</script>
<style lang="less">
	page {
		background-color: #ebebeb;
	}

	.borde {
		background-color: #fff;
		padding-top: 40rpx;
		padding-bottom: 40rpx;
		border-bottom: 2rpx solid #f1f1f1;
	}

	.flex {
		width: 100%;
	}

	// .service {
	// 	font-size: 30rpx;
	// 	text-align: left;
	// 	flex: 1;
	// 	background-color: #fff;
	// 	outline: none;
	// 	padding: 0;
	// 	color: #000;
	// 	margin-left: 10rpx;
	// }
	button[type=default] {
		font-size: 30rpx;
		text-align: left;
		flex: 1;
		background-color: #fff;
		outline: none;
		padding: 0;
		color: #000;
		margin-left: 10rpx;
	}

	button::after {
		border: none;
	}

	button[type=default]:active {
		background-color: #fff;
	}

	button[type=default]:visited {
		background-color: #fff;
	}

	/* 已访问的链接 */
	button[type=default]:link {
		background-color: #fff;
	}

	/* 未访问的链接 */
	button[type=default]:hover {
		background-color: #fff;
	}

	/* 鼠标划过链接 */

	.deposit {
		border-radius: 30rpx;
		border: 2rpx solid #999;
		padding: 10rpx 20rpx;
		margin-left: 20rpx;
	}

	.zabj {
		background-size: 100% 100%;
		-moz-background-size: 100% 100%;
		// height: 450rpx;
		padding-bottom: 120rpx;
		background-repeat: no-repeat;
		background-color: #0071FE;
		border-bottom-left-radius: 50rpx;
		border-bottom-right-radius: 50rpx;
		overflow: hidden;
	}

	.money {
		display: flex;
		justify-content: space-between;
		margin: 20rpx 44rpx;
		color: #fff;
		font-weight: bold;

		text {
			font-size: 30rpx;
		}
	}

	.moneys {
		display: flex;
		justify-content: space-between;
		align-items: center;
		text-align: center;
		margin: 20rpx 44rpx;
		color: #fff;
		font-weight: bold;

		text {
			text {
				display: block;
			}
		}
	}
</style>